import { defineStore } from 'pinia'
import { ref } from 'vue'
import { adminGetContentCountService } from '@/api/admin'
import { useUserStore } from '@/stores/user'

export const useCountStore = defineStore('big-count', () => {
  // 定义内容统计状态
  const contentCount = ref({
    notificationCount: 0,
    videoCount: 0,
    documentCount: 0,
    courseWareCount: 0,
    testPublishCount: 0,
    testLibraryCount: 0,
    testStatisticsCount: 0
  })

  // 异步获取内容统计数据
  const getContentCount = async () => {
    try {
      if (useUserStore().identify === 'teacher'){
        const res = await adminGetContentCountService()
        contentCount.value = res.data.data
      }
    } catch (error) {
      console.error('Failed to fetch content count:', error)
    }
  }

  // 手动设置内容统计数据
  const setContentCount = (newContentCount : any) => {
    contentCount.value = newContentCount
  }

  // 导出状态和方法
  return { contentCount, getContentCount: getContentCount, setContentCount: setContentCount }
})
